<?php
/**
 * @copyright  Copyright (c) 2015-2016 bearshop Inc. (http://www.smallbearshop.net)
 * @license    http://www.smallbearshop.net
 * @link       http://www.smallbearshop.net
 * @since      File available since Release v1.1
 */

class jingxuanControl extends BaseHomeControl{
	public function __construct(){
		parent::__construct();
        Language::read('indexs');
        Tpl::output('index_sign','index');
        
	}
	
	public function indexOp(){
		//Tpl::showpage('jingxuan.index');
		Tpl::showpage('zsm/jingxuan.index');
	}
	
	
	public function jingxuandataOp(){
		

		$condition = array();
		$condition['end_time'] = array('gt',time());
		$condition['is_fabu'] = 1;
		$condition['is_state'] = '0';
		$condition['yikoujia_end'] = '0';
		$condition['is_jingxuan'] = '1';
		
		$nextpage = intval($_GET['nextpage']);
		$nextnum = ($nextpage-1)*5;
		$limit = "{$nextnum},5";
		
		$model = Model();
		$field = 'auction.*,user.avatar as avatar';
		$list = $model->field($field)->table('auction,user')->join('left')->on('auction.seller_id = user.user_id')->where($condition)->limit($limit)->order('auction.id desc')->select();

		if(empty($list)) exit;
		
		foreach($list as $key=>$val){
			$list[$key]['record'] = $model->table('auction_log')->where(array('auction_id'=>$val['id']))->count();
		}
		
		Tpl::output('list',$list);
		//Tpl::showpage('jingxuan.data');
		Tpl::showpage('zsm/jingxuan.data');
	}
	
	
	/*
	 * 推荐店铺
	 */
	public function recommendstoreOp(){
				
		$model = Model();
		$recommendstore = $model->table('user')->where(array('recommend_store'=>1))->select();
		//print_R($recommendstore);exit;
		Tpl::output('recommendstore',$recommendstore);		
		//Tpl::showpage('recommend.store');
		Tpl::showpage('zsm/recommend.store');

	}
	
	/*
	 * 推荐店铺数据
	*/
	public function recommendstoredataOp(){
		
		$model = Model();
		$recommendstore = $model->table('user')->where(array('recommend_store'=>1))->select();
		
		$str = '';
		if(!empty($recommendstore)){
			foreach($recommendstore as $val){
				$str.=$val['user_id'].',';
			}
			
			$str = trim($str,',');
		}
		
		$condition = array();
		$condition['seller_id'] = array('in',$str);
		$condition['is_fabu'] = '1';
		$condition['end_time'] = array('gt',time());
		$condition['yikoujia_end'] = '0';
		
		$nextpage = intval($_GET['nextpage']);
		$nextnum = ($nextpage-1)*4;
		$limit = "{$nextnum},4";
		
		$auction_array = $model->table('auction')->where($condition)->order('id desc')->limit($limit)->select();
		if(empty($auction_array)) exit;
		
		Tpl::output('list',$auction_array);
		//Tpl::showpage('recommend.store.data');
		Tpl::showpage('zsm/recommend.store.data');
	}
	
	
}